<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
	function sosuo() {
		var lpath = location.pathname;
		var pageNo = $("#pageNo").val();
		$("#soform").attr("action", lpath + "?pageNo=" + 1);

		$("#soform").submit();
	}
</script>
</head>

<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading">
			<!--   
			<button style="float: right" type="button" onclick="addmsg()" class="btn btn-info">
				<span class="glyphicon glyphicon-plus"></span>
				&nbsp;新增消息
			</button>
			-->
			<form id="soform" method="post">
				<input type="hidden" name="so_companyId" value="${so_companyId!}">
				<table>
					<tr>
						<td class="w80" style="padding-top: 5px">
							<label for="companyname" class="center-block">员工姓名或者账号：</label>
						</td>
						<td class="w150 ">
							<input type="text" class="form-control" name="so_search" value="${so_search!}" id="so_search" placeholder="员工姓名或者账号" data-options="">
						</td>
						<td class="w80" style="padding-top: 5px; padding-left: 10px">
							<label for="companyname" class="center-block">角色类型：</label>
						</td>
						<td class="w120 ">
							<select class="form-control" name="so_roleType">
							    <option value="" [#if !so_roleType?? || so_roleType=='']selected="selected"[/#if]>全部</option>
								<option value="1" [#if so_roleType?? && so_roleType=='1']selected="selected"[/#if]>供应商</option>
								<option value="2" [#if so_roleType?? && so_roleType=='2']selected="selected"[/#if]>采购商</option>
							</select>
						</td>
						<td style="padding-left: 10px">
							<div class="input-group">
								<span class="input-group-btn">
									<button class="btn btn-default" type="button" onclick="sosuo()">搜索</button>
								</span>
							</div>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
			<thead>
				<tr>
					<th width="15%">序号</th>
					<th width="20%">用户名</th>
					<th width="15%">联系电话</th>
					<th width="20%">员工姓名</th>
					<th width="15%">所属角色</th>
					<th width="15%">操作</th>
				</tr>
			</thead>
			[#list pagination.list as user ]
			<tr>
				<td align="center">${user_index + 1}</td>
				<td align="center">
						[#if user.email??]
							邮箱:${user.email}
						[/#if]
						[#if user.mobile??]
							电话:${user.mobile}
						[/#if]
				</td>
				<td align="center">${user.contactTel!}</td>
				<td align="center">
						[#if user.realName??]
							${user.realName!}
						[#else]
							[#if user.email??]
								邮箱:${user.email}
							[/#if]
							[#if user.mobile??]
								电话:${user.mobile}
							[/#if]
						[/#if]
				</td>
				<td align="center">${user.name!}([#if user.roleType==1]采购商[#else]供应商[/#if])</td>
				<td align="center">
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="edit('${user.id!}','${user.name!}','${user.roleType!}','${user.roleId!}')">修改角色</button>
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="forbidden('${user.id!}','${user.state!}')">
						[#if user.state==0]启用该员工[#else]禁用该员工[/#if]
					</button>
				</td>
			</tr>
			[/#list]
		</table>
		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>
	
	<!-- 编辑  -->
	<div id="editUser" style="width: 600px; height: 300px; display: none;">
		<form id="editform" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="userId" id="user_id">
			<input type="hidden" name="orRoleId" id="orRoleId"><!-- 原来的roleId -->
			<div class="form-group">
				<label class="col-sm-2 control-label">新角色</label>
				<div class="col-sm-8">
					<select class="form-control" name="roleType" id="editrole">
						[#list roleList as role]
							<option value="${role.id!}">${role.name!}([#if role.roleType==1]采购商[#else]供应商[/#if])</option>
						[/#list]
					</select>
				</div>	
			</div>
			<div class="form-group" style="margin-top: 10px;">
				<div class="col-sm-offset-2 col-sm-10">
					<input id="addsubmit" type="button" onclick="subedit()" class="btn btn-default" value="提交" />
				</div>
			</div>
		</form>
	</div>
	
</body>
</html>
<script type="text/javascript">
	
	//打开编辑窗口
	function edit(userid,roleName,roleType,roleId) {
		dialog = art.dialog({
			title : "修改角色",
			lock : true,
			content : document.getElementById('editUser')
		});
		$("#user_id").val(userid);
		$("#orRoleId").val(roleId);
		/* 
		$("input[name='roleType']").children().each(function(){
			if($(this).val()==roleType){
				$(this).attr("selected","selected")
			}
		})
		*/
	}
	
	function subedit(){
		 if(confirm("是否修改当前用户角色？原本的所有角色将被替换")){
			 if($("#editrole").val()==null){
				 alert("该公司没有创建任何角色");
				 return false;
			 }
			 $.ajax({
					url : '/company/ajax_editrole.do',
					type : 'post',
					dataType : 'json',
					data :$("#editform").serialize(),
					beforeSend : function() {
						art.dialog.tips("提交中...");
					},
					success : function(data) {
						if (data.success) {
							location.reload();
						} else {
							error_msg(data.msg, function() {
								location.reload();
							});
						}
					}
				});
		 }
	}
	
	function forbidden(userId,state){
		var m='';
		if(state==0){
			m='是否启用当前员工';
		}else{
			m='是否禁用当前员工';
		}
		 if(confirm(m)){
			 $.ajax({
					url : '/company/ajax_forbidden.do',
					type : 'post',
					dataType : 'json',
					data :{userId:userId,state:state},
					beforeSend : function() {
						art.dialog.tips("提交中...");
					},
					success : function(data) {
						if (data.success) {
							location.reload();
						} else {
							error_msg(data.msg, function() {
								location.reload();
							});
						}
					}
				});
		 }
	}
	

</script>